package com.pt25.study.example.interfaces.facade.test;


import com.pt25.base.model.spi.SpiTestService;
import com.pt25.base.res.ResBody;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;
import java.util.ServiceLoader;

@Slf4j
@Tag(name = "spi test api")
@RefreshScope
@RestController
@RequestMapping("/test-api/example")
public class SpiTestController {
    private final static String TEST_SPI = "/test-spi";


    @Operation(summary = "测试SPI")
    @GetMapping(TEST_SPI)
    public ResBody testSPI() throws Exception {
        System.out.println("hello");
        return ResBody.builder().build();
    }

    public static void main(String[] args) {
        ServiceLoader<SpiTestService> spiTestServices = ServiceLoader.load(SpiTestService.class);
        Optional<SpiTestService> first = spiTestServices.findFirst();
        SpiTestService spiTestService = first.get();
        spiTestService.hello("小明");
    }
}
